import { defineConfig, loadEnv } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import path from 'path';

export default defineConfig((mode, command) => {
  const env = loadEnv(mode, process.cwd());
  console.log('🚀 ~ defineConfig ~ env:', env, 'mode', mode, 'VITE_PROXY_TARGET',env.VITE_PROXY_TARGET);

  return {
    base: '/',
    resolve: {
      alias: {
        '~': path.resolve(__dirname, './'),
        '@': path.resolve(__dirname, './src'),
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    build: {
      minify: true,
      outDir: 'dist'
    },
    server: {
      port: '80'
    },
    plugins: [
      uni(),
      Components({
        // resolvers: [ElementPlusResolver()],
        dirs: ['src/components'], // 组件目录
        extensions: ['vue'],
        dts: 'types/components.d.ts', // 生成类型声明文件
      }),
      AutoImport({
        imports: ['vue', 'pinia'], // 自动导入 Vue 和其他库函数
        dts: 'types/auto-imports.d.ts', // 生成类型声明文件
        // resolvers: [ElementPlusResolver()]
      })
    ],

    assetsInclude: [
      '**/*.png',
      '**/*.jpg',
      '**/*.jpeg',
      '**/*.gif',
      '**/*.bmp',
      '**/*.svg',
    ],
    exclude: [/\/README\.md$/]
  };
});
